package com.hmily.spring.samples.loader;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <h1>GroovyLoader验证的控制器。</h1>
 *
 * @author hmilyylimh
 * ^_^
 * @version 0.0.1
 * ^_^
 * @date 2021-10-30
 */
@RestController
public class GroovyController {

    @Autowired
    private GroovyLoader groovyLoader;

    @RequestMapping("/groovy")
    public String test(){
        // systemClassLoader 在哪里？
        String scriptBase64 = getScriptBase64();

        Object instance = groovyLoader.getBean("systemClassLoader", scriptBase64);
        ILoader loader = (ILoader) instance;
        return loader.getLoaderName();
    }

    private String getScriptBase64() {
        return "cGFja2FnZSBjb20uaG1pbHkuc3ByaW5nLnNhbXBsZXMubG9hZGVyOw0KDQovKioNCiAqIOivt+i+k+WFpeS4gOWPpee+juS4veeahOaPj+i/sOivneivrQ0KICoNCiAqIEBhdXRob3IgaG1pbHl5bGltaA0KICogXl9eDQogKiBAdmVyc2lvbiAwLjAuMQ0KICogXl9eDQogKiBAZGF0ZSAyMDIxLTEwLTMwDQogKi8NCnB1YmxpYyBjbGFzcyBTeXN0ZW1DbGFzc0xvYWRlciBpbXBsZW1lbnRzIElMb2FkZXJ7DQoNCiAgICBAT3ZlcnJpZGUNCiAgICBwdWJsaWMgU3RyaW5nIGdldExvYWRlck5hbWUoKSB7DQogICAgICAgIHJldHVybiAiU3lzdGVtQ2xhc3NMb2FkZXLoh6rlt7Hpmo/kvr/lrprkuYnnmoTkuIDkuKrlkI3lrZfov5Tlm54hISEiOw0KICAgIH0NCn0NCg==";
    }
}
